import _extends from 'babel-runtime/helpers/extends';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
/**
 * 文本输入框提示字符
 * @author: cly
 * @since: 2019-10-14
 */
import * as React from 'react';
import { Input } from 'antd';
var TextArea = Input.TextArea;

var TextAreaTips = function (_React$Component) {
    _inherits(TextAreaTips, _React$Component);

    function TextAreaTips(props) {
        _classCallCheck(this, TextAreaTips);

        var _this = _possibleConstructorReturn(this, (TextAreaTips.__proto__ || Object.getPrototypeOf(TextAreaTips)).call(this, props));

        _this.state = {
            descCount: 0
        };
        _this.componentDidMount = function () {
            if (_this.ta.textAreaRef.innerHTML) {
                _this.wordStatic(_this.ta.textAreaRef.innerHTML);
            }
        };
        _this.wordStatic = function (value) {
            var onChange = _this.props.onChange;

            value = value || '';
            if (onChange) {
                onChange(value);
            }
            _this.setState({
                descCount: value.length
            });
        };
        return _this;
    }

    _createClass(TextAreaTips, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                maxLength = _props.maxLength,
                width = _props.width;
            var descCount = this.state.descCount;

            return React.createElement(
                'div',
                { style: { position: "relative", width: width } },
                React.createElement(TextArea, _extends({}, this.props, { onChange: function onChange(e) {
                        return _this2.wordStatic(e.target.value);
                    }, ref: function ref(r) {
                        _this2.ta = r;
                    } })),
                React.createElement(
                    'div',
                    { className: 'textareaCounter' },
                    React.createElement(
                        'span',
                        { id: 'num' },
                        descCount
                    ),
                    '/',
                    maxLength,
                    '\u5B57\u7B26'
                )
            );
        }
    }]);

    return TextAreaTips;
}(React.Component);

export default TextAreaTips;